package cn.iocoder.yudao.module.system.dal.mysql.warehouse;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.system.controller.admin.warehouse.vo.GoldMaterialTransferPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.warehouse.GoldMaterialTransferDO;
import org.apache.ibatis.annotations.*;

import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

@Mapper
public interface GoldMaterialTransferMapper extends BaseMapperX<GoldMaterialTransferDO> {
    default PageResult<GoldMaterialTransferDO> selectPage(GoldMaterialTransferPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GoldMaterialTransferDO>()
                .likeIfPresent(GoldMaterialTransferDO::getTransferNo, reqVO.getTransferNo())
                .eqIfPresent(GoldMaterialTransferDO::getTransferType, reqVO.getTransferType())
                .eqIfPresent(GoldMaterialTransferDO::getFromWarehouseId, reqVO.getFromWarehouseId())
                .eqIfPresent(GoldMaterialTransferDO::getToWarehouseId, reqVO.getToWarehouseId())
                .eqIfPresent(GoldMaterialTransferDO::getStatus, reqVO.getStatus())
                .eqIfPresent(GoldMaterialTransferDO::getApproverId, reqVO.getApproverId())
                .betweenIfPresent(GoldMaterialTransferDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(GoldMaterialTransferDO::getId));
    }
    @Select("select * from gold_material_transfer where id = #{id} for update")
    GoldMaterialTransferDO selectByIdForUpdate(@Param("id") Long id);

    @Update("update gold_material_transfer set status = #{status}, approver_id = #{approverId}, " +
            "approve_time = now(), approve_remark = #{approveRemark} where id = #{id} and status = 0")
    int updateApprove(@Param("id") Long id, @Param("status") Integer status,
                      @Param("approverId") Long approverId, @Param("approveRemark") String approveRemark);
}